//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package ciicos.iview.controller;

import ciicos.base.ActionResult;
import ciicos.iview.model.iview.IviewSqlVO;
import ciicos.iview.service.IviewService;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping({"/api/iviewManage"})
public class IviewController {
    private static final Logger log = LoggerFactory.getLogger(IviewController.class);
    @Autowired
    private IviewService iviewService;

    @GetMapping({"/userlogin"})
    public ActionResult userlogin(@RequestParam(name = "user",required = true) String user, @RequestParam(name = "pass",required = true) String pass) {
        String realdata = this.iviewService.userlogin(user, pass);
        return ActionResult.success(JSONObject.parse(realdata));
    }

    @GetMapping({"/userlogout"})
    public ActionResult userlogout(@RequestParam(name = "token",required = true) String token) {
        String realdata = this.iviewService.userlogout(token);
        return ActionResult.success(JSONObject.parse(realdata));
    }

    @GetMapping({"/realdata3"})
    public ActionResult realdata(@RequestParam(name = "token",required = false) String token, @RequestParam(name = "tags",required = true) String tags, @RequestParam(name = "pars",required = true) String pars, @RequestParam(name = "decimal",required = false) Integer decimal, @RequestParam(name = "valueonly",required = false) Integer valueonly) {
        String realdata = this.iviewService.realdata(token, tags, pars, decimal, valueonly);
        return ActionResult.success(JSONObject.parse(realdata));
    }

    @GetMapping({"/realdata4"})
    public ActionResult realdata(@RequestParam(name = "token",required = false) String token, @RequestParam(name = "names",required = true) String names, @RequestParam(name = "decimal",required = false) Integer decimal, @RequestParam(name = "valueonly",required = false) Integer valueonly) {
        String realdata = this.iviewService.realdata(token, names, decimal, valueonly);
        return ActionResult.success(JSONObject.parse(realdata));
    }

    @GetMapping({"/realdir5"})
    public ActionResult realdir(@RequestParam(name = "token",required = false) String token, @RequestParam(name = "subnode",required = false) String subnode, @RequestParam(name = "recursion",required = false) Integer recursion, @RequestParam(name = "valueonly",required = false) Integer valueonly, @RequestParam(name = "decimal",required = false) Integer decimal) {
        String realdir = this.iviewService.realdir(token, subnode, recursion, valueonly, decimal);
        return ActionResult.success(JSONObject.parse(realdir));
    }

    /**
     * 注册点名
     * @param token
     * @param recursion
     * @param decimal
     * @param valueonly
     * @param nodenames
     * @return
     */

    @GetMapping({"/realdata6"})
    public ActionResult realdata(@RequestParam(name = "token",required = false) String token,
                                 @RequestParam(name = "recursion",required = false) Integer recursion,
                                 @RequestParam(name = "decimal",required = false) Integer decimal,
                                 @RequestParam(name = "valueonly",required = false) Integer valueonly,
                                 @RequestParam(name = "nodenames",required = true) String nodenames) {
        String realdata = this.iviewService.realdata(nodenames,token, recursion, decimal, valueonly);
        return ActionResult.success(JSONObject.parse(realdata));
    }

    /**
     * 注册点名
     * @param token
     * @param regname
     * @param names
     * @return
     */
    @GetMapping({"/realdata7"})
    public ActionResult realdata(@RequestParam(name = "token",required = false) String token,
                                @RequestParam(name = "regname",required = true) String regname,
                                @RequestParam(name = "names",required = true) String names) {
        String realdir = this.iviewService.realdata(token, regname, names);
        return ActionResult.success(JSONObject.parse(realdir));
    }

    /**
     * 根据注册项获取数据
     * @param token
     * @param regname
     * @param decimal
     * @return
     */
    @GetMapping({"/realdata8"})
    public ActionResult realdata(@RequestParam(name = "token",required = false) String token,
                                 @RequestParam(name = "regname",required = true) String regname,
                                 @RequestParam(name = "decimal",required = false) Integer decimal) {
        String realdir = this.iviewService.realdata(token, regname, decimal);
        return ActionResult.success(JSONObject.parse(realdir));
    }

    @GetMapping({"/realdata9"})
    public ActionResult realdata(@RequestParam(name = "token",required = false) String token, @RequestParam(name = "body",required = true) String body) {
        String realdata = this.iviewService.realdata(token, body);
        return ActionResult.success(JSONObject.parse(realdata));
    }

    @GetMapping({"/hisdata11"})
    public ActionResult hisdata(@RequestParam(name = "token",required = false) String token, @RequestParam(name = "times",required = true) String times, @RequestParam(name = "names",required = true) String names, @RequestParam(name = "decimal",required = false) Integer decimal, @RequestParam(name = "valueonly",required = false) Integer valueonly) {
        String hisdata = this.iviewService.hisdata(token, times, names, decimal, valueonly);
        return ActionResult.success(JSONObject.parse(hisdata));
    }

    @GetMapping({"/hisdata12"})
    public ActionResult hisdata(@RequestParam(name = "token",required = false) String token, @RequestParam(name = "startTime",required = true) String startTime, @RequestParam(name = "endTime",required = true) String endTime, @RequestParam(name = "interval",required = true) Integer interval, @RequestParam(name = "names",required = true) String names, @RequestParam(name = "decimal",required = false) Integer decimal, @RequestParam(name = "valueonly",required = false) Integer valueonly) {
        String hisdata = this.iviewService.hisdata(token, startTime, endTime, interval, names, decimal, valueonly);
        return ActionResult.success(JSONObject.parse(hisdata));
    }

    @PostMapping({"/sql14"})
    public ActionResult sql(@RequestParam(name = "token",required = false) String token, @RequestBody IviewSqlVO iviewSqlVO) {
        String hisdata = this.iviewService.sql(token, iviewSqlVO);
        return ActionResult.success(JSONObject.parse(hisdata));
    }

    @PostMapping({"/alarmdata15"})
    public ActionResult alarmdata(@RequestParam(name = "token",required = false) String token,
                            @RequestParam(name = "realalmcount",required = false) Integer realalmcount,
                            @RequestParam(name = "org",required = false) String org,
                            @RequestParam(name = "unit",required = false) Integer unit,
                            @RequestParam(name = "level",required = false) Integer level,
                            @RequestParam(name = "tags",required = false) String tags,
                            @RequestParam(name = "groupbytag",required = false) Integer groupbytag,
                            @RequestParam(name = "startTime",required = false) String startTime,
                            @RequestParam(name = "endTime",required = false) String endTime
                            ) {
        String hisdata = this.iviewService.alarmdata(token, realalmcount,org,unit,level,tags,groupbytag,startTime,endTime);
        return ActionResult.success(JSONObject.parse(hisdata));
    }
}
